/**
 *  * Bestpay.com.cn Inc.
 *  * Copyright (c) 2011-2017 All Rights Reserved.
 *  
 */
package elastic.job;

import TestClass.DataFlowTest;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.dataflow.DataflowJob;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
  * 
  * @author yedengfeng
  * @version Id: TestDataflowJob.java, v 0.1 2017/5/10 17:20 yedengfeng Exp $$
  */
@Slf4j
public class TestDataflowJob implements DataflowJob<DataFlowTest> {


    @Override
    public List<DataFlowTest> fetchData(ShardingContext shardingContext) {
        log.info("获取数据分片数为:"+shardingContext.getShardingItem());
        if(shardingContext.getShardingItem() == 1)
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        List<DataFlowTest> list = new ArrayList<>();
        DataFlowTest dataFlowTest = new DataFlowTest();
        list.add(dataFlowTest);
        return list;
    }

    @Override
    public void processData(ShardingContext shardingContext, List<DataFlowTest> list) {
        if(shardingContext.getShardingItem() == 1)
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        log.info("[{}]执行任务",new Date());
    }
}